const { DataTypes } = require('sequelize')
const seq = require('../db/seq')
const Goods = require('../model/goods.model')
const Carts = seq.define('cart', {
  goods_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '商品id'
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '用户id'
  },
  number: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '商品数量',
    defaultValue: 1,
  },
  selected: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: true,
    comment: '是否选中'
  }
})

// 同步数据(建表)
// Carts.sync({ 'force': true })
// 定义外键
Carts.belongsTo(Goods, {
  foreignKey: 'goods_id',
  as: "goods_info"
})
module.exports = Carts